"""Changed Discount model

Revision ID: 51432b11dcf6
Revises: 1ac71244a30e
Create Date: 2023-09-28 14:49:34.593595

"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "51432b11dcf6"
down_revision = "1ac71244a30e"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column("discount", sa.Column("shop_id", sa.Integer(), nullable=True))
    op.add_column("discount", sa.Column("category_id", sa.Integer(), nullable=True))
    op.add_column("discount", sa.Column("discount_percent", sa.Float(), nullable=False))
    op.alter_column(
        "discount",
        "required_quantity",
        existing_type=sa.Float(),
        type_=sa.Integer(),
        existing_nullable=False,
    )
    op.create_foreign_key(op.f("fk_discount_shop_id_shop"), "discount", "shop", ["shop_id"], ["id"])
    op.create_foreign_key(
        op.f("fk_discount_category_id_category"),
        "discount",
        "category",
        ["category_id"],
        ["id"],
    )
    op.drop_column("discount", "discount_type")
    op.drop_column("discount", "discount_amount")
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "discount",
        sa.Column("discount_amount", sa.Integer(), autoincrement=False, nullable=False),
    )
    op.add_column("discount", sa.Column("discount_type", sa.Enum("percent"), nullable=False))
    op.drop_constraint(op.f("fk_discount_category_id_category"), "discount", type_="foreignkey")
    op.drop_constraint(op.f("fk_discount_shop_id_shop"), "discount", type_="foreignkey")
    op.alter_column(
        "discount",
        "required_quantity",
        existing_type=sa.Integer(),
        type_=sa.Float(),
        existing_nullable=False,
    )
    op.drop_column("discount", "discount_percent")
    op.drop_column("discount", "category_id")
    op.drop_column("discount", "shop_id")
    # ### end Alembic commands ###
